package secondStage.part5.网络编程.TCP通信程序;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @ClassName: [ClientTcpSendTest]
 * @Description: TCP通信程序，发送信息
 * @Author: [黄劲松]
 * @CreateDate: [2021-04-06]
 * @Version: [v1.0]
 */
//客户端:发送数据，接收服务器反馈
public class ClientTcpSendTest {
    public static void main(String[] args) throws IOException {
        //创建客户端的Socket对象(Socket)
        Socket s = new Socket("192.168.1.115", 10086);
        //获取输出流，写数据
        OutputStream os = s.getOutputStream();
        os.write("HELLO TCP I'am coming!".getBytes());
        //接收服务器反馈
        InputStream is = s.getInputStream();
        byte[] bys = new byte[1024];
        int len = is.read(bys);
        String data = new String(bys,0,len);
        System.out.println("客户端"+data);

        s.close();
    }
}
